<?php
class PhicdsvsController extends AppController {

	var $name = 'Phicdsvs';

	function index() {
		$this->Phicdsv->recursive = 0;
		$this->set('phicdsvs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid phicdsv', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('phicdsv', $this->Phicdsv->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Phicdsv->create();
			if ($this->Phicdsv->save($this->data)) {
				$this->Session->setFlash(__('The phicdsv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The phicdsv could not be saved. Please, try again.', true));
			}
		}
		$loaichiphis = $this->Phicdsv->Loaichiphi->find('list');
		$chidoansvs = $this->Phicdsv->Chidoansv->find('list');
		$this->set(compact('loaichiphis', 'chidoansvs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid phicdsv', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Phicdsv->save($this->data)) {
				$this->Session->setFlash(__('The phicdsv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The phicdsv could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Phicdsv->read(null, $id);
		}
		$loaichiphis = $this->Phicdsv->Loaichiphi->find('list');
		$chidoansvs = $this->Phicdsv->Chidoansv->find('list');
		$this->set(compact('loaichiphis', 'chidoansvs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for phicdsv', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Phicdsv->delete($id)) {
			$this->Session->setFlash(__('Phicdsv deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Phicdsv was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
